package com.smartcruise.main.mainFragment.messageNotice;

import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.smartcruise.R;
import com.smartcruise.base.BaseTitleFragment;
import com.smartcruise.base.RefreshContract;
import com.smartcruise.base.RefreshSimpleImp;
import com.smartcruise.base.TitleBuilder;

import butterknife.BindView;

/**
 * Created by FengChaoQun
 * on 2018/1/21 0021
 * 消息通知界面
 */

public class MessageNoticeFragment extends BaseTitleFragment implements RefreshContract.View {
    @BindView(R.id.listView)
    ListView listView;
    @BindView(R.id.emptyView)
    TextView emptyView;
    @BindView(R.id.swipeRefreshLayout)
    SmartRefreshLayout swipeRefreshLayout;

    private RefreshContract.Presenter mPresenter;
    protected RefreshContract.RefreshInterface refreshInterface;

    @Override
    protected void init() {
        setCloseActivity();

        refreshInterface = new RefreshSimpleImp(swipeRefreshLayout);
        refreshInterface.setOnRefreshListener(new RefreshContract.OnRefreshListener() {
            @Override
            public void onRefresh(RefreshContract.RefreshInterface refreshInterface) {
                mPresenter.refresh();
            }
        });
        refreshInterface.setOnLoadMoreListener(new RefreshContract.OnLoadMoreListener() {
            @Override
            public void onLoadMore(RefreshContract.RefreshInterface refreshInterface) {
                mPresenter.loadMore();
            }
        });

        listView.setEmptyView(emptyView);
        listView.setDividerHeight(1);

        mPresenter = new MessagePresenterImp(this);
        mPresenter.start();
    }

    @Override
    protected int getContentLayout() {
        return R.layout.util_refresh_list;
    }

    @Override
    protected TitleBuilder getTitleBuilder() {
        return TitleBuilder.create(true, getString(R.string.messageNotice));
    }

    /**
     * description:获取刷新组件
     */
    @Override
    public RefreshContract.RefreshInterface getRefresh() {
        return refreshInterface;
    }

    @Override
    public void setData(BaseAdapter adapter) {
        listView.setAdapter(adapter);
    }

}
